var nowpage = 1
$.ajax({
    url:initObj.url + "/api/user/selectUser",
    // data:JSON.stringify(form),
    datatype:'json',
    type:'get',
    beforeSend: function(request) {
       request.setRequestHeader("token", form.token);
    },
    success:function(res){
        console.log(res)
        $('#balance').html(res.data[0].balance)
        // $('#contacts').html(res.data[0].contacts)
        contacts.value = res.data[0].contacts
        sessionStorage.setItem('contacts',res.data[0].contacts)
        // $('#idCard').html(res.data[0].idCard)
        idCard.value = res.data[0].idCard
        // $('#mechanismCode').html(res.data[0].mechanismCode)
        mechanismCode.value = res.data[0].mechanismCode
        $('#merchantNo').html(res.data[0].merchantNo)
        $('#daifu_merchantNo').html(res.data[0].merchantNo)
        // $('#realName').html(res.data[0].realName)
        realName.value = res.data[0].realName
        $('#telephone').html(res.data[0].telephone)
        $('#daifu_bankphone').html(res.data[0].telephone)
        // $('#userInformation').html(res.data[0].userInformation)
        userInformation.value = res.data[0].userInformation
        $('#username').html(res.data[0].username)
        $('#state').html(res.data[0].state)
        if(res.data[0].state == '正常'){
            document.getElementById('state').style.color = "green"
        }else{
            document.getElementById('state').style.color = "red"
        }
        $('#ip').html(res.data[1].ip)
        $('#time').html(res.data[1].time)
        $('#daifu_poundage').html(res.data[0].poundage)
        $('#huzhuan_poundage').html(res.data[0].poundage)
        $('#chongzhi_rechargeRate').html(res.data[0].rechargeRate)
    }
})
function histroyIP(){
    // $.ajax({
    //     url:initObj.url + "/api/ip/selectAllIp",
    //     // data:JSON.stringify(form),
    //     datatype:'json',
    //     type:'get',
    //     beforeSend: function(request) {
    //        request.setRequestHeader("token", form.token);
    //     },
    //     success:function(res){
    //         console.log(res)
    //     }
    // })
    window.location.href = "../safe/safe.html"
}

//代付
function daifu_show(){
    daifu_bankPhone.value = telephone.innerHTML
    document.getElementById('daifu_show').style.display = "block"
    // daifu_limit.style.display = 'none'
}
function daifu_close(){
    document.getElementById('daifu_show').style.display = "none"
}
function daifu_get(){
    $.ajax({
        url:initObj.url + '/api/sms/sendSms/' + daifu_bankPhone.value + '/代付',
        type:'get',
        datatype:'json',
        success:function(res){
            console.log(res)
            alert(res.msg)
        }
    })
    // document.getElementById('send_sms_login').style.backgroundColor = "#e3e3ec"
    var timer2 = 60
    $("#daifu_get").attr("disabled", "disabled");
    var timer1 = setInterval(() => {
        timer2--;
        console.log(timer2)
        document.getElementById('daifu_get').innerHTML = timer2 + "秒后重新发送"
        if(timer2 == 0){
            console.log('stop')
            $("#daifu_get").removeAttr("disabled");
            // document.getElementById('send_sms_login').style.backgroundColor = 'rgba(62, 65, 242,0.7)'
            document.getElementById('daifu_get').innerHTML = '免费获取验证码'
            clearInterval(timer1)
        }
    }, 1000);
}
daifu_amount.onblur = function(){
    console.log(1)
}
function daifu_OK(){
    var form_daifu = {
        bankUsername: daifu_bankUsername.value,
        bankCard: daifu_bankCard.value,
        // bankPhone: daifu_bankPhone.value,
        bankName: daifu_bankName.value,
        // body: daifu_body.value,
        amount: daifu_amount.value,
        code: daifu_code1.value,
        payPassword:hex_md5(daifu_password.value)
    }
    $.ajax({
        url:initObj.url + "/api/cashOrder/cash",
        data:JSON.stringify(form_daifu),
        datatype:'json',
        type:'post',
        contentType: "application/json;charset=utf-8",
        beforeSend: function(request) {
           request.setRequestHeader("token", form.token);
        },
        success:function(res){
            console.log(res)
            alert(res.msg)   
        }
    })
}
//充值
function chongzhi_show(){
    chongzhi_info()
    document.getElementById('chongzhi_show').style.display = "block"
}
function chongzhi_close(){
    document.getElementById('chongzhi_show').style.display = "none"
}
var form_chongzhi = {}
function chongzhi_OK(){
    console.log(form_chongzhi)
    form_chongzhi.bankUsername = chongzhi_bankUsername.value
    form_chongzhi.bankCard = chongzhi_bankCard.value
    form_chongzhi.amount = chongzhi_amount.value
    console.log(form_chongzhi)
    $.ajax({
        url:initObj.url + "/api/recharge",
        data:JSON.stringify(form_chongzhi),
        datatype:'json',
        type:'post',
        contentType: "application/json;charset=utf-8",
        beforeSend: function(request) {
           request.setRequestHeader("token", form.token);
        },
        success:function(res){
            console.log(res)
            alert(res.msg)   
        }
    })
}
function chongzhi_info(){
    $.ajax({
        url:initObj.url + "/api/rechargeInfo/findOne",
        datatype:'json',
        type:'get',
        // contentType: "application/json;charset=utf-8",
        beforeSend: function(request) {
           request.setRequestHeader("token", form.token);
        },
        success:function(res){
            // console.log(res)
            $('#chongzhi_name').html(res.data.name)
            $('#chongzhi_rechargeBankCard').html(res.data.bankCard) 
            $('#chongzhi_bankNameSon').html(res.data.bankNameSon)
            $('#chongzhi_bankName').html(res.data.bankName)
            // form_chongzhi.id = res.data.id
            form_chongzhi.rechargeBankCard = chongzhi_rechargeBankCard.innerHTML
            form_chongzhi.rechargeBankMainSon = chongzhi_bankNameSon.innerHTML
            form_chongzhi.rechargeBankMain = chongzhi_bankName.innerHTML
            console.log(form_chongzhi)
        }
    })
}
function chongzhi_yujidaozhang(){
    document.getElementById('chongzhi_yujidaozhang').innerHTML = (parseFloat(chongzhi_amount.value) * (1 - parseFloat(chongzhi_rechargeRate.innerHTML))).toFixed(2)
    chongzhi_jisuan.style.display = "block"
}

//互转

function huzhuan_show(){
    huzhuan_bankPhone.value = telephone.innerHTML
    document.getElementById('huzhuan_show').style.display = 'block'
}
function huzhuan_close(){
    document.getElementById('huzhuan_show').style.display = 'none'
}
function huzhuan_get(){
    console.log(huzhuan_bankPhone.value)
    $.ajax({
        url:initObj.url + '/api/sms/sendSms/' + huzhuan_bankPhone.value + '/互转',
        type:'get',
        datatype:'json',
        success:function(res){
            console.log(res)
            alert(res.msg)
        }
    })
    // document.getElementById('send_sms_login').style.backgroundColor = "#e3e3ec"
    var timer2 = 60
    $("#huzhuan_get").attr("disabled", "disabled");
    var timer1 = setInterval(() => {
        timer2--;
        console.log(timer2)
        document.getElementById('huzhuan_get').innerHTML = timer2 + "秒后重新发送"
        if(timer2 == 0){
            console.log('stop')
            $("#huzhuan_get").removeAttr("disabled");
            // document.getElementById('send_sms_login').style.backgroundColor = 'rgba(62, 65, 242,0.7)'
            document.getElementById('huzhuan_get').innerHTML = '免费获取验证码'
            clearInterval(timer1)
        }
    }, 1000);
}
function huzhuan_OK(){
    var form_huzhuan = {
        receivedMerchant : huzhuan_merchantNo.value,
        username : huzhuan_username.value,
        bankPhone:huzhuan_bankPhone.value,
        phoneCode:huzhuan_phonecode.value,
        payPassword:hex_md5(huzhuan_password.value),
        amount : huzhuan_amount.value
    }
    console.log(form_huzhuan)
    $.ajax({
        url:initObj.url + "/api/transfer",
        data:JSON.stringify(form_huzhuan),
        datatype:'json',
        type:'post',
        contentType: "application/json;charset=utf-8",
        beforeSend: function(request) {
           request.setRequestHeader("token", form.token);
        },
        success:function(res){
            console.log(res)
            alert(res.msg)   
        }
    })
}

//财务报表
function go_caiwubaobiao(){
    window.location.href = 'caiwubaobiao.html'
}

//重置
console.log(sessionStorage.getItem('firstLogin'))
if(sessionStorage.getItem('firstLogin') == 'true'){
    console.log(sessionStorage.getItem('firstLogin'))
    reset_show.style.display = 'block'
}
function reset_get(){
    $.ajax({
        url:initObj.url + '/api/sms/sendSms/' + reset_phone.value + '/第一次登录',
        type:'get',
        datatype:'json',
        success:function(res){
            console.log(res)
            alert(res.msg)
        }
    })
    // document.getElementById('send_sms_login').style.backgroundColor = "#e3e3ec"
    var timer2 = 60
    $("#reset_get").attr("disabled", "disabled");
    var timer1 = setInterval(() => {
        timer2--;
        // console.log(timer2)
        document.getElementById('reset_get').innerHTML = timer2 + "秒后重新发送"
        if(timer2 == 0){
            console.log('stop')
            $("#reset_get").removeAttr("disabled");
            // document.getElementById('send_sms_login').style.backgroundColor = 'rgba(62, 65, 242,0.7)'
            document.getElementById('reset_get').innerHTML = '免费获取验证码'
            clearInterval(timer1)
        }
    }, 1000);
}
function reset_OK(){
    form_reset = {
        telephone : reset_phone.value,
        password : hex_md5(reset_safepassword.value),
        payPassword : hex_md5(reset_zhifupassword.value)
    }
    $.ajax({
        url:initObj.url + "/api/user/bindUserInfo/" + reset_phonecode.value,
        data:JSON.stringify(form_reset),
        datatype:'json',
        type:'post',
        contentType: "application/json;charset=utf-8",
        beforeSend: function(request) {
           request.setRequestHeader("token", form.token);
        },
        success:function(res){
            console.log(res)
            alert(res.msg)  
            if(res.msg == '请求成功'){
                sessionStorage.setItem('firstLogin',false)
                reset_show.style.display = 'none'
            }   
        }
    })
}
//保存
function update_save(){
        var form_save = {
            userInformation:userInformation.value,
            contacts:contacts.value,
            realName:realName.value,
            idCard:idCard.value,
            mechanismCode:mechanismCode.value
        }
        $.ajax({
            url:initObj.url + "/api/user/updateUserInfo",
            data:JSON.stringify(form_save),
            datatype:'json',
            type:'post',
            contentType: "application/json;charset=utf-8",
            beforeSend: function(request) {
               request.setRequestHeader("token", form.token);
            },
            success:function(res){
                console.log(res)
                alert(res.msg)
            }
        })
}